
// 用户ID
let id = getUrlParam("id");
$(function () {
    GetUserRole();
});
//获取用户权限
function GetUserRole() {
    // let thisdata = [];
    // thisdata.push(InitRole(id));
    let USERdata = InitRole(id);
    if (USERdata != null) {
        initCombox();

    }
    else OpenErrmsg("../../web/errhtml/404.html");
}
function initCombox() {
    let data = [];
    let thisdate = new Date();
    let thisyear = thisdate.getFullYear();
    let count = thisyear - 2018;
    for (let index = 0; index <= count; index++) {
        let element = 2018 + index;
        let text = element + "年";

        data.push({
            'id': element, 'text': text
        });
    }
    $('#com_Year').combobox({
        data: data,
        valueField: 'id',
        textField: 'text',
        onSelect: function (record) {
            InitData(record.id);
            InitChart(record.id);
        },
        onLoadSuccess: function (data) {
            if (data.length > 0) {
                let datacount = data.length - 1;
                let thisid = data[datacount].id;
                $('#com_Year').combobox("setValue", thisid);
                InitData(thisid);
                InitChart(thisid);
            }

        }
    });
}
//加载数据列表
function InitData(year) {
    console.log(year)
    let data = [
        { "inventoryturnover": "60", "department": "全部费用", "inventoryamount": "10" },
        { "inventoryturnover": "30", "department": "生产部门", "inventoryamount": "1" },
        { "inventoryturnover": "30", "department": "电气部门", "inventoryamount": "200" },
        { "inventoryturnover": "30", "department": "仪表部门", "inventoryamount": "200" },
        { "inventoryturnover": "30", "department": "外输部门", "inventoryamount": "200" },
        { "inventoryturnover": "30", "department": "化验部门", "inventoryamount": "200" },
        { "inventoryturnover": "20", "department": "机械部门", "inventoryamount": "200" },
        { "inventoryturnover": "20", "department": "计控部门", "inventoryamount": "200" }
    ];
    $('#dg_DateList').datagrid({
        data: data
    });
}
//加载图表
function InitChart() {
    let data = [
        { "name": "冷工", "qty": "6" },
        { "name": "进入限制空间", "qty": "8" },
        { "name": "热工", "qty": "3" },
    ];
    var myChart = echarts.init(document.getElementById('chartdiv'));
    var xAxisDataLine = new Array();
    var seriesDataLine = new Array();
    // for (var i = 0; i < data.length; i++) {
    //     var item = data[i];
    //     xAxisDataLine.push(item.name)
    //     seriesDataLine.push({
    //         value: item.qty,
    //         // type:'bar',
    //         // barWidth:'40px',
    //         itemStyle: {
    //             color: colorArr[i].color
    //         }
    //     });
    // }
    // 指定图表的配置项和数据
    var option = {
        // 全局调色盘。
        color: ['#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3'],
        legend: {},
        tooltip: {},
        dataset: {
            source: [
                ['department', '本期', '同期',],
                ['安全', 43.3, 93.7],
                ['生产', 83.1, 73.4],
                ['系泊', 86.4, 65.2],
                ['维修', 72.4, 53.9]
            ]
        },
        xAxis: { type: 'category' },
        yAxis: {},
        // Declare several bar series, each will be mapped
        // to a column of dataset.source by default.
        series: [{ type: 'bar' }, { type: 'bar' }]
    };
    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);

}

function formaterinventoryturnover(value, row) {
    return value + "%";
}
